/**
 * 检测报告
 */
var localStorageManagers = require("script/localStorageManagers.js");
//mui初始化
mui.init({
	swipeBack: true
});
//plus初始化
mui.plusReady(function() {
	plusReady();
});
//plusReady
function plusReady() {
	var self=plus.webview.currentWebview();
	document.getElementById('catalogid').value=self.catalogid;
	document.getElementById('catalogname').value=self.catalogname;
	document.getElementById('resid').value=self.resid;
	document.getElementById('resname').value=self.resname;
	document.getElementById('testtitle').innerText=self.resname;
	//加载随堂jiance
	loadTestreportDiv();
	//打开课题对应的笔记列表
	mui('#nav-mui-bar').on('tap', '#viewanalysis', openTestanalysis);
	//返回随堂主页面
	//mui('header').on('tap','#backtestindex',backTestindex);
};
//加载笔记列表
function loadTestreportDiv() {
	ajaxLoadTestreport();
}
//ajax加载报告
function ajaxLoadTestreport(){
	var userid = localStorageManagers.getUseridSession();
	var resid = plus.webview.currentWebview().resid;
	var url=serverAjax+'/mobile/classroomtest/getExamReport.do';
	mui.ajax(url, {
		data: {
			userid: userid,
			resid: resid
		},
		type: 'post',
		dataType: 'json',
		timeout: 10000,
		success: function(data) {
			if (data == null) return;
			buildTestreportDiv(data);
		},
		error: function(e1, e2, e3) {
			ajaxErrorTip();
			console.log(e1);
		}
	});
}
//buildTestreportDiv
function buildTestreportDiv(data){
	var tihaosEle=document.getElementById('tihaos');
	var rightnum=0;
	for(var i=0;i<data.length;i++){
		var entry=data[i];
		var act='';
		if(entry.isRight==0){
			act='act';
		}else{
			rightnum++;
		}
		var tihaostr='<span class="tihao '+act+'">'+(i+1)+'</span>';
		tihaosEle.innerHTML=tihaosEle.innerHTML+tihaostr;
	}
	document.getElementById('rightnum').innerHTML='&nbsp;答对了'+rightnum+'&nbsp;道题';
	document.getElementById('total').innerHTML='共&nbsp;'+data.length+'&nbsp;道题';
	document.getElementById('stotal').innerHTML='/'+data.length;
	document.getElementById('sright').innerHTML=rightnum;
};
//打开检测解析
function openTestanalysis(){
	var catalogid =document.getElementById('catalogid').value;
	var catalogname = document.getElementById('catalogname').value;
	var resid = document.getElementById('resid').value;
	var resname = document.getElementById('resname').value;
	var data = {
		catalogid: catalogid,
		catalogname: catalogname,
		resid: resid,
		resname: resname
	};
	mui.openWindow({
		url:'testanalysis.html',
		id:'selfcenter/classroomtest/testanalysis',
		extras:data
	});
};
mui.back=function(){
		var parentWebView = plus.webview.getWebviewById("selfcenter/classroomtest/testindex");
	    parentWebView.evalJS("loadNoteDiv()");
		mui.openWindow({
		id:'selfcenter/classroomtest/testindex'
	});
}
//返回随堂检测主页面
function backTestindex(){
	//	mui.openWindow({
	//	id:'selfcenter/classroomtest/testindex'
	//});
};
